﻿using System;
using System.Collections.Generic;
using Character;
using H;
using UnityEngine;

// Token: 0x02000243 RID: 579
public class H_VisitorVoice : MonoBehaviour
{
	// Token: 0x06000F8C RID: 3980 RVA: 0x00063264 File Offset: 0x00061464
	public void Setup()
	{
		CustomDataListLoader customDataListLoader = new CustomDataListLoader();
		customDataListLoader.Load(this.voiceList);
		int attributeNo = customDataListLoader.GetAttributeNo("タイプ");
		int attributeNo2 = customDataListLoader.GetAttributeNo("詳細");
		int attributeNo3 = customDataListLoader.GetAttributeNo("ファイル");
		int attributeNo4 = customDataListLoader.GetAttributeNo("初回");
		int attributeNo5 = customDataListLoader.GetAttributeNo("抵抗");
		int attributeNo6 = customDataListLoader.GetAttributeNo("豹変");
		int attributeNo7 = customDataListLoader.GetAttributeNo("豹変淫語");
		for (int i = 0; i < customDataListLoader.GetDataNum(); i++)
		{
			string data = customDataListLoader.GetData(attributeNo, i);
			string data2 = customDataListLoader.GetData(attributeNo2, i);
			string data3 = customDataListLoader.GetData(attributeNo3, i);
			string data4 = customDataListLoader.GetData(attributeNo4, i);
			string data5 = customDataListLoader.GetData(attributeNo5, i);
			string data6 = customDataListLoader.GetData(attributeNo6, i);
			string data7 = customDataListLoader.GetData(attributeNo7, i);
			H_VisitorVoice.TYPE type = (H_VisitorVoice.TYPE)H_VisitorVoice.StringsCheck(H_VisitorVoice.TypeNames, data);
			H_VisitorVoice.DETAIL detail = (H_VisitorVoice.DETAIL)H_VisitorVoice.StringsCheck(H_VisitorVoice.DetailNames, data2);
			int num = this.Number(data4);
			int num2 = this.Number(data5);
			int num3 = this.Number(data6);
			int num4 = this.Number(data7);
			this.AddData(type, detail, data3, H_VisitorVoice.STATE.FIRST, H_VisitorVoice.FileStateNo[0], num);
			this.AddData(type, detail, data3, H_VisitorVoice.STATE.RESIST, H_VisitorVoice.FileStateNo[1], num2);
			this.AddData(type, detail, data3, H_VisitorVoice.STATE.FLOP, H_VisitorVoice.FileStateNo[2], num3);
			if (num4 > 0)
			{
				this.AddData(type, detail, data3, H_VisitorVoice.STATE.FLOP_INDECENT, H_VisitorVoice.FileStateNo[3], num4);
			}
			else
			{
				this.AddData(type, detail, data3, H_VisitorVoice.STATE.FLOP_INDECENT, H_VisitorVoice.FileStateNo[2], num3);
			}
		}
	}

	// Token: 0x06000F8D RID: 3981 RVA: 0x00063408 File Offset: 0x00061608
	private int Number(string check)
	{
		if (check == "-")
		{
			return -1;
		}
		int result = -1;
		try
		{
			result = int.Parse(check);
		}
		catch
		{
			GlobalData.Debug_LogError("数字変換失敗:" + check);
		}
		return result;
	}

	// Token: 0x06000F8E RID: 3982 RVA: 0x0006345C File Offset: 0x0006165C
	private void AddData(H_VisitorVoice.TYPE type, H_VisitorVoice.DETAIL detail, string fileBase, H_VisitorVoice.STATE state, string stateNoStr, int num)
	{
		for (int i = 0; i < num; i++)
		{
			string text = fileBase.Replace("yy", stateNoStr);
			int num2 = text.LastIndexOf("_");
			string s = text.Substring(num2 + 1);
			int num3 = int.Parse(s);
			text = text.Substring(0, num2 + 1);
			text += (num3 + i).ToString("00");
			this.datas.Add(new H_VisitorVoice.Data(type, state, detail, text));
		}
	}

	// Token: 0x06000F8F RID: 3983 RVA: 0x000634E4 File Offset: 0x000616E4
	private static int StringsCheck(string[] strings, string check)
	{
		for (int i = 0; i < strings.Length; i++)
		{
			if (check == strings[i])
			{
				return i;
			}
		}
		return -1;
	}

	// Token: 0x06000F90 RID: 3984 RVA: 0x00063518 File Offset: 0x00061718
	public H_VisitorVoice.Data Voice(Female female, H_VoiceLog log, AssetBundleController voiceABC, H_VisitorVoice.TYPE type, H_Members members)
	{
		H_VisitorVoice.Data data = this.GetData(female, log, type, members);
		if (data != null)
		{
			string fileName = this.GetFileName(female.HeroineID, data);
			AudioClip audioClip = voiceABC.LoadAsset<AudioClip>(fileName);
			if (audioClip == null)
			{
				GlobalData.Debug_LogError("没有声音剪辑：" + fileName);
			}
			female.PhonationVoice(audioClip, false);
			bool flag = false;
			if (data.type == H_VisitorVoice.TYPE.ACT || data.type == H_VisitorVoice.TYPE.AFTER)
			{
				flag = true;
			}
			else if (data.detail == H_VisitorVoice.DETAIL.PRIOLITY)
			{
				flag = true;
			}
			if (flag)
			{
				log.AddPriorityTalk(data.file);
			}
			else
			{
				log.AddPant(data.file);
			}
			return data;
		}
		return null;
	}

	// Token: 0x06000F91 RID: 3985 RVA: 0x000635C8 File Offset: 0x000617C8
	private H_VisitorVoice.Data GetData(Female female, H_VoiceLog log, H_VisitorVoice.TYPE type, H_Members members)
	{
		H_VisitorVoice.Data result = null;
		List<H_VisitorVoice.Data> list = new List<H_VisitorVoice.Data>();
		foreach (H_VisitorVoice.Data data in this.datas)
		{
			if (data.Check(female, type, members))
			{
				list.Add(data);
			}
		}
		if (list.Count > 0)
		{
			log.Check(list);
			if (list.Count == 0)
			{
				return null;
			}
			this.CheckPriority(list);
			int index = UnityEngine.Random.Range(0, list.Count);
			result = list[index];
		}
		return result;
	}

	// Token: 0x06000F92 RID: 3986 RVA: 0x0006367C File Offset: 0x0006187C
	private void CheckPriority(List<H_VisitorVoice.Data> datas)
	{
		bool flag = false;
		for (int i = 0; i < datas.Count; i++)
		{
			if (datas[i].detail == H_VisitorVoice.DETAIL.PRIOLITY)
			{
				flag = true;
				break;
			}
		}
		if (flag)
		{
			for (int j = 0; j < datas.Count; j++)
			{
				if (datas[j].detail != H_VisitorVoice.DETAIL.PRIOLITY)
				{
					datas.RemoveAt(j);
					j--;
				}
			}
		}
	}

	// Token: 0x06000F93 RID: 3987 RVA: 0x000636F8 File Offset: 0x000618F8
	private string GetFileName(HEROINE heroine, H_VisitorVoice.Data data)
	{
		if (data != null)
		{
			return H_VisitorVoice.HeroinePrefix[(int)heroine] + "_" + data.file;
		}
		return string.Empty;
	}

	// Token: 0x0400106E RID: 4206
	private static readonly string[] HeroinePrefix = new string[]
	{
		"r",
		"a",
		"y",
		"m"
	};

	// Token: 0x0400106F RID: 4207
	private static readonly string[] FileStateNo = new string[]
	{
		"90",
		"00",
		"10",
		"11"
	};

	// Token: 0x04001070 RID: 4208
	private static readonly string[] TypeNames = new string[]
	{
		"呼吸",
		"行為",
		"事後",
		"かけられ",
		"汎用"
	};

	// Token: 0x04001071 RID: 4209
	private static readonly string[] DetailNames = new string[]
	{
		"-",
		"口塞がれ",
		"性器挿入",
		"アナル挿入",
		"奉仕",
		"咥え",
		"舐め",
		"コキ",
		"対律子（抵抗）",
		"対律子（豹変）",
		"対明子（抵抗）",
		"対明子（豹変）",
		"対雪子（抵抗）",
		"対雪子（豹変）",
		"対真理子（抵抗）",
		"対真理子（豹変）",
		"対広一",
		"脱力",
		"アヘ",
		"絶頂（汎用）",
		"絶頂（性器）",
		"絶頂（アナル）",
		"中出し（性器,アナル）",
		"中出し（性器）",
		"中出し（アナル）",
		"外出し",
		"口内射精",
		"優先",
		"悔しい",
		"それなり",
		"嬉しい"
	};

	// Token: 0x04001072 RID: 4210
	[SerializeField]
	private TextAsset voiceList;

	// Token: 0x04001073 RID: 4211
	private List<H_VisitorVoice.Data> datas = new List<H_VisitorVoice.Data>();

	// Token: 0x02000244 RID: 580
	public enum TYPE
	{
		// Token: 0x04001075 RID: 4213
		BREATH,
		// Token: 0x04001076 RID: 4214
		ACT,
		// Token: 0x04001077 RID: 4215
		AFTER,
		// Token: 0x04001078 RID: 4216
		LIQUID,
		// Token: 0x04001079 RID: 4217
		GENERAL,
		// Token: 0x0400107A RID: 4218
		NUM
	}

	// Token: 0x02000245 RID: 581
	public enum STATE
	{
		// Token: 0x0400107C RID: 4220
		FIRST,
		// Token: 0x0400107D RID: 4221
		RESIST,
		// Token: 0x0400107E RID: 4222
		FLOP,
		// Token: 0x0400107F RID: 4223
		FLOP_INDECENT,
		// Token: 0x04001080 RID: 4224
		NUM
	}

	// Token: 0x02000246 RID: 582
	public enum DETAIL
	{
		// Token: 0x04001082 RID: 4226
		NONE,
		// Token: 0x04001083 RID: 4227
		GAG,
		// Token: 0x04001084 RID: 4228
		INSERT_VAGINA,
		// Token: 0x04001085 RID: 4229
		INSERT_ANAL,
		// Token: 0x04001086 RID: 4230
		SERVICE,
		// Token: 0x04001087 RID: 4231
		IN_MOUTH,
		// Token: 0x04001088 RID: 4232
		LICK,
		// Token: 0x04001089 RID: 4233
		JOB,
		// Token: 0x0400108A RID: 4234
		TO_RITSUKO_RESIST,
		// Token: 0x0400108B RID: 4235
		TO_RITSUKO_FLOP,
		// Token: 0x0400108C RID: 4236
		TO_AKIKO_RESIST,
		// Token: 0x0400108D RID: 4237
		TO_AKIKO_FLOP,
		// Token: 0x0400108E RID: 4238
		TO_YUKIKO_RESIST,
		// Token: 0x0400108F RID: 4239
		TO_YUKIKO_FLOP,
		// Token: 0x04001090 RID: 4240
		TO_MARIKO_RESIST,
		// Token: 0x04001091 RID: 4241
		TO_MARIKO_FLOP,
		// Token: 0x04001092 RID: 4242
		TO_KOUICHI,
		// Token: 0x04001093 RID: 4243
		WEAKNESS,
		// Token: 0x04001094 RID: 4244
		AHE,
		// Token: 0x04001095 RID: 4245
		XTC_GENERAL,
		// Token: 0x04001096 RID: 4246
		XTC_VAGINA,
		// Token: 0x04001097 RID: 4247
		XTC_ANAL,
		// Token: 0x04001098 RID: 4248
		EJA_IN_V_A,
		// Token: 0x04001099 RID: 4249
		EJA_IN_VAGINA,
		// Token: 0x0400109A RID: 4250
		EJA_IN_ANAL,
		// Token: 0x0400109B RID: 4251
		OUT_EJA,
		// Token: 0x0400109C RID: 4252
		EJA_IN_MOUTH,
		// Token: 0x0400109D RID: 4253
		PRIOLITY,
		// Token: 0x0400109E RID: 4254
		BAD,
		// Token: 0x0400109F RID: 4255
		SOSO,
		// Token: 0x040010A0 RID: 4256
		GOOD,
		// Token: 0x040010A1 RID: 4257
		NUM
	}

	// Token: 0x02000247 RID: 583
	public class Data
	{
		// Token: 0x06000F95 RID: 3989 RVA: 0x000638D0 File Offset: 0x00061AD0
		public Data(H_VisitorVoice.TYPE type, H_VisitorVoice.STATE state, H_VisitorVoice.DETAIL detail, string file)
		{
			this.type = type;
			this.state = state;
			this.detail = detail;
			this.file = file;
		}

		// Token: 0x06000F96 RID: 3990 RVA: 0x000638F8 File Offset: 0x00061AF8
		public bool Check(Female female, H_VisitorVoice.TYPE type, H_Members members)
		{
			return this.CheckType(type) && this.CheckState(female, this.state) && this.CheckDetail(female, members);
		}

		// Token: 0x06000F97 RID: 3991 RVA: 0x0006392C File Offset: 0x00061B2C
		private bool CheckType(H_VisitorVoice.TYPE type)
		{
			return this.type == type || ((type == H_VisitorVoice.TYPE.ACT || type == H_VisitorVoice.TYPE.AFTER) && this.type == H_VisitorVoice.TYPE.GENERAL);
		}

		// Token: 0x06000F98 RID: 3992 RVA: 0x0006395C File Offset: 0x00061B5C
		private bool CheckState(Female female, H_VisitorVoice.STATE state)
		{
			if (state == H_VisitorVoice.STATE.FIRST)
			{
				return female.personality.state == Personality.STATE.FIRST;
			}
			if (state == H_VisitorVoice.STATE.RESIST)
			{
				return !female.IsFloped();
			}
			if (state == H_VisitorVoice.STATE.FLOP)
			{
				return female.IsFloped() && !female.personality.indecentLanguage;
			}
			return state == H_VisitorVoice.STATE.FLOP_INDECENT && female.IsFloped() && female.personality.indecentLanguage;
		}

		// Token: 0x06000F99 RID: 3993 RVA: 0x000639D8 File Offset: 0x00061BD8
		private bool CheckDetail(Female female, H_Members members)
		{
			H_StyleData.TYPE type = (members.StyleData == null) ? H_StyleData.TYPE.NUM : members.StyleData.type;
			int num = (members.StyleData == null) ? 0 : members.StyleData.detailFlag;
			XTC_TYPE xtcType = members.param.xtcType;
			if (this.detail == H_VisitorVoice.DETAIL.GAG)
			{
				return female.Gag;
			}
			if (female.Gag)
			{
				return false;
			}
			if (this.detail == H_VisitorVoice.DETAIL.INSERT_VAGINA)
			{
				return type == H_StyleData.TYPE.INSERT && (num & 16) != 0;
			}
			if (this.detail == H_VisitorVoice.DETAIL.INSERT_ANAL)
			{
				return type == H_StyleData.TYPE.INSERT && (num & 32) != 0;
			}
			if (this.detail == H_VisitorVoice.DETAIL.SERVICE)
			{
				return type == H_StyleData.TYPE.SERVICE;
			}
			if (this.detail == H_VisitorVoice.DETAIL.IN_MOUTH)
			{
				return type == H_StyleData.TYPE.SERVICE && (num & H_StyleData.DetailMasking_InMouth) != 0;
			}
			if (this.detail == H_VisitorVoice.DETAIL.LICK)
			{
				return type == H_StyleData.TYPE.SERVICE && (num & 2) != 0;
			}
			if (this.detail == H_VisitorVoice.DETAIL.JOB)
			{
				return type == H_StyleData.TYPE.SERVICE && (num & H_StyleData.DetailMasking_UseMouth) == 0;
			}
			if (this.detail == H_VisitorVoice.DETAIL.TO_RITSUKO_RESIST)
			{
				if (female.HeroineID == HEROINE.MARIKO)
				{
					return false;
				}
				List<Female> females = members.GetFemales();
				for (int i = 0; i < females.Count; i++)
				{
					if (females[i].HeroineID == HEROINE.RITSUKO && !females[i].IsFloped())
					{
						return true;
					}
				}
				return false;
			}
			else if (this.detail == H_VisitorVoice.DETAIL.TO_RITSUKO_FLOP)
			{
				if (female.HeroineID == HEROINE.MARIKO)
				{
					return false;
				}
				List<Female> females2 = members.GetFemales();
				for (int j = 0; j < females2.Count; j++)
				{
					if (females2[j].HeroineID == HEROINE.RITSUKO && females2[j].IsFloped())
					{
						return true;
					}
				}
				return false;
			}
			else if (this.detail == H_VisitorVoice.DETAIL.TO_AKIKO_RESIST)
			{
				if (female.HeroineID == HEROINE.MARIKO)
				{
					return false;
				}
				List<Female> females3 = members.GetFemales();
				for (int k = 0; k < females3.Count; k++)
				{
					if (females3[k].HeroineID == HEROINE.AKIKO && !females3[k].IsFloped())
					{
						return true;
					}
				}
				return false;
			}
			else if (this.detail == H_VisitorVoice.DETAIL.TO_AKIKO_FLOP)
			{
				if (female.HeroineID == HEROINE.MARIKO)
				{
					return false;
				}
				List<Female> females4 = members.GetFemales();
				for (int l = 0; l < females4.Count; l++)
				{
					if (females4[l].HeroineID == HEROINE.AKIKO && females4[l].IsFloped())
					{
						return true;
					}
				}
				return false;
			}
			else if (this.detail == H_VisitorVoice.DETAIL.TO_YUKIKO_RESIST)
			{
				if (female.HeroineID == HEROINE.MARIKO)
				{
					return false;
				}
				List<Female> females5 = members.GetFemales();
				for (int m = 0; m < females5.Count; m++)
				{
					if (females5[m].HeroineID == HEROINE.YUKIKO && !females5[m].IsFloped())
					{
						return true;
					}
				}
				return false;
			}
			else if (this.detail == H_VisitorVoice.DETAIL.TO_YUKIKO_FLOP)
			{
				if (female.HeroineID == HEROINE.MARIKO)
				{
					return false;
				}
				List<Female> females6 = members.GetFemales();
				for (int n = 0; n < females6.Count; n++)
				{
					if (females6[n].HeroineID == HEROINE.YUKIKO && females6[n].IsFloped())
					{
						return true;
					}
				}
				return false;
			}
			else if (this.detail == H_VisitorVoice.DETAIL.TO_MARIKO_RESIST)
			{
				if (female.HeroineID == HEROINE.MARIKO)
				{
					return false;
				}
				List<Female> females7 = members.GetFemales();
				for (int num2 = 0; num2 < females7.Count; num2++)
				{
					if (females7[num2].HeroineID == HEROINE.MARIKO && !females7[num2].IsFloped())
					{
						return true;
					}
				}
				return false;
			}
			else if (this.detail == H_VisitorVoice.DETAIL.TO_MARIKO_FLOP)
			{
				if (female.HeroineID == HEROINE.MARIKO)
				{
					return false;
				}
				List<Female> females8 = members.GetFemales();
				for (int num3 = 0; num3 < females8.Count; num3++)
				{
					if (females8[num3].HeroineID == HEROINE.MARIKO && females8[num3].IsFloped())
					{
						return true;
					}
				}
				return false;
			}
			else if (this.detail == H_VisitorVoice.DETAIL.TO_KOUICHI)
			{
				if (female.HeroineID == HEROINE.MARIKO)
				{
					return false;
				}
				List<Male> males = members.GetMales();
				for (int num4 = 0; num4 < males.Count; num4++)
				{
					if (males[num4].MaleID == MALE_ID.KOUICHI)
					{
						return true;
					}
				}
				return false;
			}
			else
			{
				if (this.detail == H_VisitorVoice.DETAIL.WEAKNESS)
				{
					return members.GetFemale(0).personality.weakness;
				}
				if (this.detail == H_VisitorVoice.DETAIL.AHE)
				{
					return members.GetFemale(0).personality.ahe;
				}
				if (this.detail == H_VisitorVoice.DETAIL.XTC_GENERAL)
				{
					return xtcType == XTC_TYPE.XTC_F || xtcType == XTC_TYPE.XTC_W;
				}
				if (this.detail == H_VisitorVoice.DETAIL.XTC_VAGINA)
				{
					return (xtcType == XTC_TYPE.XTC_F || xtcType == XTC_TYPE.XTC_W) && (num & 16) != 0;
				}
				if (this.detail == H_VisitorVoice.DETAIL.XTC_ANAL)
				{
					return (xtcType == XTC_TYPE.XTC_F || xtcType == XTC_TYPE.XTC_W) && (num & 32) != 0;
				}
				if (this.detail == H_VisitorVoice.DETAIL.EJA_IN_V_A)
				{
					return (xtcType == XTC_TYPE.EJA_IN || xtcType == XTC_TYPE.XTC_W) && type == H_StyleData.TYPE.INSERT;
				}
				if (this.detail == H_VisitorVoice.DETAIL.EJA_IN_VAGINA)
				{
					return (xtcType == XTC_TYPE.EJA_IN || xtcType == XTC_TYPE.XTC_W) && (num & 16) != 0;
				}
				if (this.detail == H_VisitorVoice.DETAIL.EJA_IN_ANAL)
				{
					return (xtcType == XTC_TYPE.EJA_IN || xtcType == XTC_TYPE.XTC_W) && (num & 32) != 0;
				}
				if (this.detail == H_VisitorVoice.DETAIL.OUT_EJA)
				{
					return members.param.xtcType == XTC_TYPE.EJA_OUT;
				}
				if (this.detail == H_VisitorVoice.DETAIL.EJA_IN_MOUTH)
				{
					return xtcType == XTC_TYPE.EJA_IN && (num & H_StyleData.DetailMasking_InMouth) != 0;
				}
				if (this.detail == H_VisitorVoice.DETAIL.PRIOLITY)
				{
					return true;
				}
				if (this.detail == H_VisitorVoice.DETAIL.BAD)
				{
					return !female.IsFloped() && !female.personality.likeSperm;
				}
				if (this.detail == H_VisitorVoice.DETAIL.SOSO)
				{
					return (!female.IsFloped() && female.personality.likeSperm) || (female.IsFloped() && !female.personality.likeSperm);
				}
				return this.detail != H_VisitorVoice.DETAIL.GOOD || (female.IsFloped() && female.personality.likeSperm);
			}
		}

		// Token: 0x040010A2 RID: 4258
		public H_VisitorVoice.TYPE type;

		// Token: 0x040010A3 RID: 4259
		public H_VisitorVoice.STATE state;

		// Token: 0x040010A4 RID: 4260
		public H_VisitorVoice.DETAIL detail;

		// Token: 0x040010A5 RID: 4261
		public string file;
	}
}
